import { RuleGroupList } from "../rules";
import { Param } from "./types";

export const GlobalParamList: Param[] = [
    {
        name: "allowed-confusables",
        descEn: `A list of allowed "confusable" Unicode characters to ignore when enforcing RUF001, RUF002, and RUF003.`,
        descCn: "",
        defaultValue: [],
        url: "https://beta.ruff.rs/docs/settings/#allowed-confusables",
    },
    {
        name: "builtins",
        descEn: "A list of builtins to treat as defined references, in addition to the system builtins.",
        descCn: "",
        defaultValue: [],
        url: "https://beta.ruff.rs/docs/settings/#builtins",
    },
    {
        name: "cache-dir",
        descEn: `A path to the cache directory.

        By default, Ruff stores cache results in a .ruff_cache directory in the current project root.
        
        However, Ruff will also respect the RUFF_CACHE_DIR environment variable, which takes precedence over that default.
        
        This setting will override even the RUFF_CACHE_DIR environment variable, if set.`,
        descCn: "",
        defaultValue: ".ruff_cache",
        url: "https://beta.ruff.rs/docs/settings/#cache-dir",
    },
    {
        name: "dummy-variable-rgx",
        descEn: `A regular expression used to identify "dummy" variables, or those which should be ignored when enforcing (e.g.) unused-variable rules. The default expression matches _, __, and _var, but not _var_.`,
        descCn: "",
        defaultValue: "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$",
        url: "https://beta.ruff.rs/docs/settings/#dummy-variable-rgx",
    },
    {
        name: "exclude",
        descEn: `A list of file patterns to exclude from linting.

        Exclusions are based on globs, and can be either:
        
        Single-path patterns, like .mypy_cache (to exclude any directory named .mypy_cache in the tree), foo.py (to exclude any file named foo.py), or foo_*.py (to exclude any file matching foo_*.py ).
        Relative patterns, like directory/foo.py (to exclude that specific file) or directory/*.py (to exclude any Python files in directory). Note that these paths are relative to the project root (e.g., the directory containing your pyproject.toml).`,
        descCn: "",
        defaultValue: [".bzr", ".direnv", ".eggs", ".git", ".hg", ".mypy_cache", ".nox", ".pants.d", ".pytype", ".ruff_cache", ".svn", ".tox", ".venv", "__pypackages__", "_build", "buck-out", "build", "dist", "node_modules", "venv"],
        url: "https://beta.ruff.rs/docs/settings/#exclude",
    },
    {
        name: "extend",
        descEn: `A path to a local pyproject.toml file to merge into this configuration. User home directory and environment variables will be expanded.

        To resolve the current pyproject.toml file, Ruff will first resolve this base configuration file, then merge in any properties defined in the current configuration file.`,
        descCn: "",
        defaultValue: null,
        demoValue: "../pyproject.toml",
        url: "https://beta.ruff.rs/docs/settings/#extend",
    },
    {
        name: "extend-exclude",
        descEn: `A list of file patterns to omit from linting, in addition to those specified by exclude.

        Exclusions are based on globs, and can be either:
        
        Single-path patterns, like .mypy_cache (to exclude any directory named .mypy_cache in the tree), foo.py (to exclude any file named foo.py), or foo_*.py (to exclude any file matching foo_*.py ).
        Relative patterns, like directory/foo.py (to exclude that specific file) or directory/*.py (to exclude any Python files in directory). Note that these paths are relative to the project root (e.g., the directory containing your pyproject.toml).`,
        descCn: "",
        defaultValue: [],
        url: "https://beta.ruff.rs/docs/settings/#extend-exclude",
    },
    {
        name: "extend-include",
        descEn: `A list of file patterns to include when linting, in addition to those specified by include.

        Inclusion are based on globs, and should be single-path patterns, like *.pyw, to include any file with the .pyw extension.`,
        descCn: "",
        defaultValue: [],
        url: "https://beta.ruff.rs/docs/settings/#extend-include",
    },
    {
        name: "extend-select",
        descEn: "A list of rule codes or prefixes to enable, in addition to those specified by select.",
        descCn: "",
        defaultValue: [],
        url: "https://beta.ruff.rs/docs/settings/#extend-select",
        ruleSelect: true,
    },
    {
        name: "external",
        descEn: "A list of rule codes that are unsupported by Ruff, but should be preserved when (e.g.) validating # noqa directives. Useful for retaining # noqa directives that cover plugins not yet implemented by Ruff.",
        descCn: "",
        defaultValue: [],
        url: "https://beta.ruff.rs/docs/settings/#external",
    },
    {
        name: "fix",
        descEn: "Enable autofix behavior by-default when running ruff (overridden by the --fix and --no-fix command-line flags).",
        descCn: "",
        defaultValue: false,
        url: "https://beta.ruff.rs/docs/settings/#fix",
    },
    {
        name: "fix-only",
        descEn: "Like fix, but disables reporting on leftover violation. Implies fix.",
        descCn: "",
        defaultValue: false,
        url: "https://beta.ruff.rs/docs/settings/#fix-only",
    },
    {
        name: "fixable",
        descEn: "A list of rule codes or prefixes to consider autofixable. By default, all rules are considered autofixable.",
        descCn: "",
        defaultValue: ["A", "ANN", "ARG", "B", "BLE", "C", "COM", "D", "DTZ", "E", "EM", "ERA", "EXE", "F", "FBT", "G", "I", "ICN", "INP", "ISC", "N", "PD", "PGH", "PIE", "PL", "PT", "PTH", "Q", "RET", "RUF", "S", "SIM", "T", "TCH", "TID", "TRY", "UP", "W", "YTT"],
        url: "https://beta.ruff.rs/docs/settings/#fixable",
        ruleSelect: true,
    },
    {
        name: "force-exclude",
        descEn: `Whether to enforce exclude and extend-exclude patterns, even for paths that are passed to Ruff explicitly. Typically, Ruff will lint any paths passed in directly, even if they would typically be excluded. Setting force-exclude = true will cause Ruff to respect these exclusions unequivocally.

        This is useful for pre-commit, which explicitly passes all changed files to the ruff-pre-commit plugin, regardless of whether they're marked as excluded by Ruff's own settings.`,
        descCn: "",
        defaultValue: false,
        url: "https://beta.ruff.rs/docs/settings/#force-exclude",
    },
    {
        name: "format",
        descEn: `The style in which violation messages should be formatted: "text" (default), "grouped" (group messages by file), "json" (machine-readable), "junit" (machine-readable XML), "github" (GitHub Actions annotations), "gitlab" (GitLab CI code quality report), "pylint" (Pylint text format) or "azure" (Azure Pipeline logging commands).`,
        descCn: "",
        defaultValue: "text",
        optionList: ["text", "json", "junit", "github", "gitlab", "pylint", "azure"],
        url: "https://beta.ruff.rs/docs/settings/#format",
    },
    {
        name: "ignore",
        descEn: `A list of rule codes or prefixes to ignore. Prefixes can specify exact rules (like F841), entire categories (like F), or anything in between.

        When breaking ties between enabled and disabled rules (via select and ignore, respectively), more specific prefixes override less specific prefixes.`,
        descCn: "",
        defaultValue: [],
        url: "https://beta.ruff.rs/docs/settings/#ignore",
        ruleSelect: true,
    },
    {
        name: "ignore-init-module-imports",
        descEn: "Avoid automatically removing unused imports in __init__.py files. Such imports will still be flagged, but with a dedicated message suggesting that the import is either added to the module's __all__ symbol, or re-exported with a redundant alias (e.g., import os as os).",
        descCn: "",
        defaultValue: false,
        url: "https://beta.ruff.rs/docs/settings/#ignore-init-module-imports",
    },
    {
        name: "include",
        descEn: `A list of file patterns to include when linting.

        Inclusion are based on globs, and should be single-path patterns, like *.pyw, to include any file with the .pyw extension.`,
        descCn: "",
        defaultValue: ["*.py", "*.pyi"],
        url: "https://beta.ruff.rs/docs/settings/#include",
    },
    {
        name: "line-length",
        descEn: "The line length to use when enforcing long-lines violations (like E501).",
        descCn: "",
        defaultValue: 88,
        url: "https://beta.ruff.rs/docs/settings/#line-length",
    },
    {
        name: "namespace-packages",
        descEn: "Mark the specified directories as namespace packages. For the purpose of module resolution, Ruff will treat those directories as if they contained an __init__.py file.",
        descCn: "",
        defaultValue: [],
        url: "https://beta.ruff.rs/docs/settings/#namespace-packages",
    },
    {
        name: "per-file-ignores",
        descEn: "A list of mappings from file pattern to rule codes or prefixes to exclude, when considering any matching files.",
        descCn: "",
        defaultValue: {},
        url: "https://beta.ruff.rs/docs/settings/#per-file-ignores",
        validValue: (value: unknown) => {
            if (typeof value !== "object") {
                return "配置值必须是对象";
            }
            for (const v of Object.values(value as object)) {
                if (!Array.isArray(v)) {
                    return "对象值必须是字符串数组";
                }
                for (const ruleCode of (v as unknown[])) {
                    if (typeof ruleCode !== "string") {
                        return "对象值必须是字符串数组";
                    }
                    let match = false;
                    for (const rg of RuleGroupList) {
                        for (const rule of rg.ruleList) {
                            if (rule.code == ruleCode) {
                                match = true;
                                break;
                            }
                        }
                    }
                    if (!match) {
                        return `未知规则${ruleCode}`
                    }
                }
            }
            return null;
        },
    },
    {
        name: "required-version",
        descEn: "Require a specific version of Ruff to be running (useful for unifying results across many environments, e.g., with a pyproject.toml file).",
        descCn: "",
        defaultValue: null,
        demoValue: "0.0.193",
        url: "https://beta.ruff.rs/docs/settings/#required-version",
    },
    {
        name: "respect-gitignore",
        descEn: "Whether to automatically exclude files that are ignored by .ignore, .gitignore, .git/info/exclude, and global gitignore files. Enabled by default.",
        descCn: "",
        defaultValue: true,
        url: "https://beta.ruff.rs/docs/settings/#respect-gitignore",
    },
    {
        name: "select",
        descEn: `A list of rule codes or prefixes to enable. Prefixes can specify exact rules (like F841), entire categories (like F), or anything in between.

        When breaking ties between enabled and disabled rules (via select and ignore, respectively), more specific prefixes override less specific prefixes.`,
        descCn: "",
        defaultValue: ["E", "F"],
        url: "https://beta.ruff.rs/docs/settings/#select",
        ruleSelect: true,
    },
    {
        name: "show-fixes",
        descEn: "Whether to show an enumeration of all autofixed lint violations (overridden by the --show-fixes command-line flag).",
        descCn: "",
        defaultValue: false,
        url: "https://beta.ruff.rs/docs/settings/#show-fixes",
    },
    {
        name: "show-source",
        descEn: "Whether to show source code snippets when reporting lint violations (overridden by the --show-source command-line flag).",
        descCn: "",
        defaultValue: false,
        url: "https://beta.ruff.rs/docs/settings/#show-source",
    },
    {
        name: "src",
        descEn: "The source code paths to consider, e.g., when resolving first- vs. third-party imports.",
        descCn: "",
        defaultValue: ["."],
        url: "https://beta.ruff.rs/docs/settings/#src",
    },
    {
        name: "target-version",
        descEn: `The Python version to target, e.g., when considering automatic code upgrades, like rewriting type annotations.

        If omitted, the target version will be inferred from the project.requires-python field in the relevant pyproject.toml (e.g., requires-python = ">=3.8"), if present.`,
        descCn: "",
        defaultValue: "py310",
        optionList: ["py37", "py38", "py39", "py310", "py311"],
        url: "https://beta.ruff.rs/docs/settings/#target-version",
    },
    {
        name: "task-tags",
        descEn: `A list of task tags to recognize (e.g., "TODO", "FIXME", "XXX").

        Comments starting with these tags will be ignored by commented-out code detection (ERA), and skipped by line-length rules (E501) if ignore-overlong-task-comments is set to true.`,
        descCn: "",
        defaultValue: ["TODO", "FIXME", "XXX"],
        url: "https://beta.ruff.rs/docs/settings/#task-tags",
    },
    {
        name: "typing-modules",
        descEn: `A list of modules whose imports should be treated equivalently to members of the typing module.

        This is useful for ensuring proper type annotation inference for projects that re-export typing and typing_extensions members from a compatibility module. If omitted, any members imported from modules apart from typing and typing_extensions will be treated as ordinary Python objects.`,
        descCn: "",
        defaultValue: [],
        url: "https://beta.ruff.rs/docs/settings/#typing-modules",
    },
    {
        name: "unfixable",
        descEn: "A list of rule codes or prefixes to consider non-autofix-able.",
        descCn: "",
        defaultValue: [],
        ruleSelect: true,
        url: "https://beta.ruff.rs/docs/settings/#unfixable",
    },
    {
        name: "update-check",
        descEn: "Enable or disable automatic update checks (overridden by the --update-check and --no-update-check command-line flags).",
        descCn: "",
        defaultValue: false,
        url: "https://beta.ruff.rs/docs/settings/#update-check",
    },
];